package g;

import javax.annotation.Nullable;

/* compiled from: Segment */
public final class v {
    public final byte[] a;
    public int b;
    public int c;
    public boolean d;
    public boolean e;
    public v f;
    public v g;

    public v() {
        this.a = new byte[8192];
        this.e = true;
        this.d = false;
    }

    @Nullable
    public final v a() {
        v vVar = this.f;
        v vVar2 = vVar != this ? vVar : null;
        v vVar3 = this.g;
        vVar3.f = vVar;
        this.f.g = vVar3;
        this.f = null;
        this.g = null;
        return vVar2;
    }

    public final v b(v vVar) {
        vVar.g = this;
        vVar.f = this.f;
        this.f.g = vVar;
        this.f = vVar;
        return vVar;
    }

    public final v c() {
        this.d = true;
        return new v(this.a, this.b, this.c, true, false);
    }

    public final void d(v vVar, int i) {
        if (vVar.e) {
            int i2 = vVar.c;
            if (i2 + i > 8192) {
                if (vVar.d) {
                    throw new IllegalArgumentException();
                }
                int i3 = i2 + i;
                int i4 = vVar.b;
                if (i3 - i4 <= 8192) {
                    byte[] bArr = vVar.a;
                    System.arraycopy(bArr, i4, bArr, 0, i2 - i4);
                    vVar.c -= vVar.b;
                    vVar.b = 0;
                } else {
                    throw new IllegalArgumentException();
                }
            }
            System.arraycopy(this.a, this.b, vVar.a, vVar.c, i);
            vVar.c += i;
            this.b += i;
            return;
        }
        throw new IllegalArgumentException();
    }

    public v(byte[] bArr, int i, int i2, boolean z, boolean z2) {
        this.a = bArr;
        this.b = i;
        this.c = i2;
        this.d = z;
        this.e = z2;
    }
}
